define(function(require, exports, module) {
	var $ = require('jquery')
	var Spine = require('spine')
	require('jquery.tmpl')
	require('../../lib/fancybox/jquery.fancybox')
	var UploadControl = Spine.Controller.sub({
		elements: {
			'#upload-file-list': 'filelist',
			'.dialog-actions': 'actions',
			'#fileinput-button': 'inputbutton',
			'.done-button': 'donebutton'
		},
		events: {
			'click #fileinput-button>button': 'addUploadFiles',
			'click .done-button': function() {
				$.fancybox.close()
				this.model.destroy()
			}
		},
		init: function() {
			App.bind('open', this.proxy(function(file) {
				this.model.updateAttributes({
					'name': file.filename,
					'path': file.path
				})
			}))
			this.model.bind('create', this.proxy(this.render))
			this.model.bind('update', this.proxy(this.render))
			this.model.bind('destroy', this.release)
		},
		addUploadFiles: function(event) {
			var folder = this.model.name
			var path = this.model.path
			var list = this.filelist
			$('#fileinput-button>input').click()
		},
		render: function() {
			this.replace($("#uploadControlTemplate").tmpl(this.model))
			return this
		}
	})
	module.exports = UploadControl
	var App = require('./app')
})